package com.anzia.study_2.slice;

import com.anzia.study_2.ResourceTable;
import com.anzia.study_2.utils.DeviceUtils;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.ability.IAbilityContinuation;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.IntentParams;
import ohos.agp.components.Button;
import ohos.agp.components.TextField;

public class MigrationBackAbilitySlice extends AbilitySlice implements IAbilityContinuation {

	private TextField textField;
	private Button mgbBtn1;
	private Button mgbBtn2;
	String tfStr = "";

	@Override
	public void onStart(Intent intent) {
		super.onStart(intent);
		super.setUIContent(ResourceTable.Layout_ability_migration_back);

		textField = (TextField) findComponentById(ResourceTable.Id_textfield_migration_back);
		textField.setText(tfStr);

		mgbBtn1 = (Button) findComponentById(ResourceTable.Id_migration_back_button1);
		mgbBtn1.setClickedListener(component -> {
			String deviceId = DeviceUtils.getDeviceId();
			if (deviceId != null) {
				// 可撤回的迁移
				continueAbilityReversibly(deviceId);
			}
		});

		mgbBtn2 = (Button) findComponentById(ResourceTable.Id_migration_back_button2);
		mgbBtn2.setClickedListener(component -> {
			reverseContinueAbility();
		});


	}

	@Override
	public void onActive() {
		super.onActive();
	}

	@Override
	public void onForeground(Intent intent) {
		super.onForeground(intent);
	}

	@Override
	public boolean onStartContinuation() {
		return true;
	}

	@Override
	public boolean onSaveData(IntentParams intentParams) {
		intentParams.setParam("data", textField.getText());
		return true;
	}

	@Override
	public boolean onRestoreData(IntentParams intentParams) {
		tfStr = intentParams.getParam("data").toString();
		return true;
	}

	@Override
	public void onCompleteContinuation(int i) {

	}
}
